package cn.rkylin.oms.order.adapter;

import cn.rkylin.apollo.common.util.BeanUtils;
import cn.rkylin.oms.common.base.AbstractAdapterFactory;
import cn.rkylin.oms.system.shop.vo.ShopVO;

/**
 * 订单适配器工厂
 *
 * @author wangxiaoyi
 * @version 1.0
 * @created 13-1月-2017 09:11:14
 */
public class OrderAdapterFactory extends AbstractAdapterFactory {
    /**
     * 构造函数
     */
    private OrderAdapterFactory() {

    }

    /**
     * 根据shopId，使用shopService获取该项目，再判断shopType创建具体的adapter
     *
     * @param shopId
     */
    public static OrderAdapter getOrderAdapter(String shopId) {
        OrderAdapter orderAdaptor = null;
        ShopVO shop = getShop(shopId);
        // 获取店铺，以得到店铺的rds地址、帐号、密码
        if (shop != null && shop.getShopType().equals("淘宝")) {

            // 不分单的情况
            if ("n".equalsIgnoreCase(shop.getNeedSplitOrder())) {
                orderAdaptor = BeanUtils.getBean("taobaoOrderAdapterWithoutSplit");
                //orderAdaptor = BeanUtils.getBean("taobaoOrderAdapter");
            } else {
                orderAdaptor = BeanUtils.getBean("taobaoOrderAdapter");
            }

            if ("rds".equals(shop.getConnMode())) {
                orderAdaptor.setOrderVisitor((TaoBaoOrderVisitor) BeanUtils.getBean("taoBaoOrderVisitor"));
            } else {
                orderAdaptor.setOrderVisitor((TaoBaoOrderVisitor) BeanUtils.getBean("taoBaoOrderVisitor"));
            }

        } else if (shop != null && "小V铺".equals(shop.getShopType())) {
            orderAdaptor = BeanUtils.getBean("xvpOrderAdapter");
            orderAdaptor.setOrderVisitor((XvpOrderVisitor) BeanUtils.getBean("xvpOrderVisitor"));
        } else if (shop != null && "唯品会直发".equals(shop.getShopType())) {
            orderAdaptor = BeanUtils.getBean("vipOrderAdapter");
            orderAdaptor.setOrderVisitor((VipOrderVisitor) BeanUtils.getBean("vipOrderVisitor"));
        }

        return orderAdaptor;
    }

}